package com.example.demo.controller;

import com.example.demo.model.CompileRequest;
import com.example.demo.service.CompileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.HashSet;

/**
 * Created by xiebang
 * Description
 * User:小谢
 * Date:2022-09-20
 * Time:9:08
 */
@Controller
@ResponseBody
public class CompileController {
    @Autowired
    private CompileService compileService;
    @RequestMapping("/compile")
    public HashMap<String,Object> compileAndRun(@RequestBody CompileRequest compileRequest){
        HashMap<String,Object> map = new HashMap<>();
        Integer error = 3;
        String reason = "代码为空";
        String stdout = "";
        if(compileRequest.id != null && StringUtils.hasLength(compileRequest.code)){
            // 说明有代码输入
          return  compileService.compileAndRun(compileRequest);
        }
        map.put("error",error);
        map.put("reason",reason);
        map.put("stdout",stdout);
        return  map;
    }


}
